package cn.dengta.webapp.user.entity.game;

import cn.dengta.webapp.base.entity.BaseEntity;
import cn.dengta.webapp.base.entity.TimeBasedEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import me.codeplayer.util.Cmp;

/**
 * 游戏复活记录
 */
@Setter
@Getter
@Accessors(chain = true)
@TableName("dt_game_rebirth_log")
public class GameRebirthLog extends TimeBasedEntity {

	/** 用户id */
	private Long userId;
	/** 游戏id */
	private Long gameId;
	/** 关联类型 */
	private String assocType;
    /** 关联目标 */
	private Long assocId;
	/** 关联目标数值：比如钻石数量 */
	private Integer assocNum;
	/** 0=未使用；1=已使用 */
	private Integer status;

	protected transient BaseEntity assocObj;

	public static GameRebirthLog of(Long userId, Long gameId) {
		GameRebirthLog log= new GameRebirthLog();
		log.setUserId(userId);
		log.setGameId(gameId);
		log.status = 0; // 1=未使用
		return log;
	}

	/** 判断是否可用 */
	public boolean isAvailable(){
		return Cmp.eq(this.status, 0);
	}

	public void handleAssocObject(BaseEntity obj) {
		this.assocObj = obj;
		this.assocType = obj.entityName();
		this.assocId = obj.getId();
	}
}
